<template>
    <div >
        <el-container>
            <el-container>

                <el-aside width="200px">
                    <el-scrollbar height="650px">                        
                        <TreeCommponent v-if="oneTableData != null" :treeData="oneTableData"
                            @treeComponent="treeComponent" :defaultExpandAll="true" :showCheckBox="false">
                        </TreeCommponent>
                    </el-scrollbar>
                </el-aside>
                <el-main>
                    <el-space>
                        <el-form-item label="试卷类型">
                            <el-select v-model="selectValueAndModel" placeholder="没有选择" @change="changeMethod1">
                                <el-option label="全部" :value="0" />
                                <el-option
                                    v-for="item in store.state.questionBank.subjectModel.testPaperTypeList"
                                    :key="item.testPaperTypeId" :label="item.testPaperTypeName"
                                    :value="item.testPaperTypeId" />
                            </el-select>
                        </el-form-item>
                        <el-form-item label="发布">
                            <el-select v-model="statusValueAndModel" placeholder="没有选择" @change="changeMethod2">
                                <el-option label="全部" :value="0" />
                                <el-option label="已发布" :value="1" />
                                <el-option label="待发布" :value="2" />
                            </el-select>
                        </el-form-item>
                        <el-form-item>
                          <MyAddTestPaperComponent></MyAddTestPaperComponent>
                        </el-form-item>
                        <el-form-item>
                          <MyDeleteListComponent></MyDeleteListComponent>
                        </el-form-item>
                    </el-space>
                    <MyTestPaperTableComponent v-loading.fullscreen.lock="loadingShow"></MyTestPaperTableComponent>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>

<script>
import TreeCommponent from '@/components/LeEn_questionBank/ReuseComponent/TreeCommponent'
import axios from 'axios';
import { ref } from '@vue/reactivity';
import { useStore } from 'vuex'
import { onMounted } from '@vue/runtime-core';
import MyTestPaperTableComponent from '../useComponent/MyTestPaperTableComponent.vue';
import MyAddTestPaperComponent from "@/components/LeEn_questionBank/test_paper/useComponent/MyAddTestPaperComponent";
import MyDeleteListComponent from "@/components/LeEn_questionBank/test_paper/useComponent/MyDeleteListComponent";
export default {
  components: {MyDeleteListComponent, MyAddTestPaperComponent, TreeCommponent, MyTestPaperTableComponent },
  setup(){
    let loadingShow = ref(false)
    //树形组件
    const store = new useStore()
    let oneTableData = ref(null)
    
    //数据渲染
    onMounted(()=>{
            loadingShow.value = true
            
                oneTableData.value = store.state.questionBank.subjectModel.subjectTypeTreeData
            
                axios.get("/api/testPaper/initializationTestPaperPage", {
                    params: {
                        testPaperTypeId: store.state.questionBank.subjectModel.testPaperPagination.testPaperTypeId,
                        accountTypeId: store.state.questionBank.subjectModel.testPaperPagination.accountTypeId,
                        status: store.state.questionBank.subjectModel.testPaperPagination.status,
                        pageNumber: store.state.questionBank.subjectModel.testPaperPagination.pageNum,
                        pageSize: store.state.questionBank.subjectModel.testPaperPagination.pageSize
                    }
                }).then((response) => {
                    if (response.status == 200) {
                        if (response.data.code == 200) {
                            let data = {
                                total: response.data.data.test_paper.total,
                                pageNum: 1,
                                pageSize: store.state.questionBank.subjectModel.testPaperPagination.pageSize,
                                accountTypeId: store.state.questionBank.subjectModel.testPaperPagination.accountTypeId,
                                testPaperTypeId: store.state.questionBank.subjectModel.testPaperPagination.testPaperTypeId,
                                status: store.state.questionBank.subjectModel.testPaperPagination.status,
                                testPaperTypeList: response.data.data.test_paper_type
                            }
                           //data.total = response.data.data.total
                            store.commit('insertSubjectPageTreeData', response.data.data.account.data)
                            store.commit('setTestPaperTableData', response.data.data.test_paper.list)
                            store.commit('setTestPaperPagination', data)
                            store.commit("selecttestPaperTypeList",response.data.data.test_paper_type)
                            oneTableData.value = response.data.data.account.data
                        }
                    }
                }).finally(() => {
                    loadingShow.value = false
                })
            
        
        })
        //tree点击返回
        function treeComponent(a){
            let data = {
                total: store.state.questionBank.subjectModel.testPaperPagination.total,
                pageNum: 1,
                pageSize: store.state.questionBank.subjectModel.testPaperPagination.pageSize,
                accountTypeId: store.state.questionBank.subjectModel.testPaperPagination.accountTypeId,
                testPaperTypeId: store.state.questionBank.subjectModel.testPaperPagination.testPaperTypeId,
                status: store.state.questionBank.subjectModel.testPaperPagination.status,

            }
            if(!a.level){
                
                data.accountTypeId = a.industryId
                store.commit('setTestPaperPagination',data)
                loadingShow.value = true

                axios.get("/api/testPaper/selectPageTestPaper",{
                    params:{
                        testPaperTypeId: store.state.questionBank.subjectModel.testPaperPagination.testPaperTypeId,
                        accountTypeId: store.state.questionBank.subjectModel.testPaperPagination.accountTypeId,
                        status: store.state.questionBank.subjectModel.testPaperPagination.status,
                        pageNumber: store.state.questionBank.subjectModel.testPaperPagination.pageNum,
                        pageSize: store.state.questionBank.subjectModel.testPaperPagination.pageSize
                    }
                }).then((response)=>{
                    if(response.status==200){
                        if(response.data.code==200){
                              data.total = response.data.data.total
                             store.commit('setTestPaperPagination', data)
                             store.commit('setTestPaperTableData', response.data.data.list)
                        }
                    }
                }).finally(()=>{
                    loadingShow.value = false
                })
            }
        }
        //***********************************************************************8 */
        let selectValueAndModel = ref(0)//用户选择查看的试卷类型
        let statusValueAndModel = ref(0)//用户选择查看的发布状态
        function changeMethod1(){//用户改变值触发,试卷类型
            let data = {
                total: store.state.questionBank.subjectModel.testPaperPagination.total,
                pageNum: 1,
                pageSize: store.state.questionBank.subjectModel.testPaperPagination.pageSize,
                accountTypeId: store.state.questionBank.subjectModel.testPaperPagination.accountTypeId,
                testPaperTypeId: store.state.questionBank.subjectModel.testPaperPagination.testPaperTypeId,
                status: store.state.questionBank.subjectModel.testPaperPagination.status,

            }
            
            data.testPaperTypeId = selectValueAndModel.value
            loadingShow.value = true
            store.commit('setTestPaperPagination',data)
            axios.get("/api/testPaper/selectPageTestPaper",{
                    params:{
                        testPaperTypeId: store.state.questionBank.subjectModel.testPaperPagination.testPaperTypeId,
                        accountTypeId: store.state.questionBank.subjectModel.testPaperPagination.accountTypeId,
                        status: store.state.questionBank.subjectModel.testPaperPagination.status,
                        pageNumber: store.state.questionBank.subjectModel.testPaperPagination.pageNum,
                        pageSize: store.state.questionBank.subjectModel.testPaperPagination.pageSize
                    }
                }).then((response)=>{
                    if(response.status==200){
                        if(response.data.code==200){
                             data.total = response.data.data.total
                             store.commit('setTestPaperPagination', data)
                             store.commit('setTestPaperTableData', response.data.data.list)

                        }
                    }
                }).finally(()=>{
                    loadingShow.value = false
                })
        }
        function changeMethod2(){//用户改变值触发,发布状态
            let data = {
               total: store.state.questionBank.subjectModel.testPaperPagination.total,
                pageNum: 1,
                pageSize: store.state.questionBank.subjectModel.testPaperPagination.pageSize,
                accountTypeId: store.state.questionBank.subjectModel.testPaperPagination.accountTypeId,
                testPaperTypeId: store.state.questionBank.subjectModel.testPaperPagination.testPaperTypeId,
                status: store.state.questionBank.subjectModel.testPaperPagination.status,

            }
            data.status = statusValueAndModel.value
            loadingShow.value = true
            store.commit('setTestPaperPagination',data)
            axios.get("/api/testPaper/selectPageTestPaper",{
                    params:{
                        testPaperTypeId: store.state.questionBank.subjectModel.testPaperPagination.testPaperTypeId,
                        accountTypeId: store.state.questionBank.subjectModel.testPaperPagination.accountTypeId,
                        status: store.state.questionBank.subjectModel.testPaperPagination.status,
                        pageNumber: store.state.questionBank.subjectModel.testPaperPagination.pageNum,
                        pageSize: store.state.questionBank.subjectModel.testPaperPagination.pageSize
                    }
                }).then((response)=>{
                    if(response.status==200){
                        if(response.data.code==200){
                            data.total = response.data.data.total
                             store.commit('setTestPaperPagination', data)
                             store.commit('setTestPaperTableData', response.data.data.list)
                        }
                    }
                }).finally(()=>{
                    loadingShow.value = false
                })
        }
        return {
            loadingShow,
            oneTableData,
            treeComponent,
            selectValueAndModel,
            statusValueAndModel,
            changeMethod1,
            changeMethod2,
            store
        }
  }

}
</script>

<style>

</style>